package com.yan.service;

/**
 * Created by yanl_ on 2018/5/6.
 */

import com.yan.bean.User;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yan.mapper.UserMapper;

import java.util.List;

@Service
public class User1Service {

  private Logger logger = LoggerFactory.getLogger(getClass());

    @Autowired
    private UserMapper user1Mapper;

    public List<User> getUsers()
    {
        List<User> users = user1Mapper.getAll();
        return(users);
    }
    /**
     *  @Transactional(value="test1TransactionManager",rollbackFor = Exception.class,timeout=36000)
     说明针对Exception异常也进行回滚，如果不标注，则Spring 默认只有抛出 RuntimeException才会回滚事务
        事物方法中，如果使用trycatch捕获异常后，需要将异常抛出，否则事物不回滚。
     */
    public void  inserUser(User user) {
        try{
            user1Mapper.insert(user);
            logger.info(String.valueOf(user));
        }catch(Exception e){
            logger.error("find exception:{}",e,e.getMessage());
            throw e;
        }
    }
}